FROM  python:3.11-slim-bullseye
# 设置工作目录
WORKDIR /app

# 设置时区为上海时区
# 在bullseye版本中，由于文件配置不需要移动该文件
# RUN mv /etc/apt/sources.list.d/debian.sources   /etc/apt/sources.list.d/debian.sources.bak
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&  echo "Asia/Shanghai" > /etc/timezone

WORKDIR /app
# 彻底删除其他源配置
RUN rm -f /etc/apt/sources.list /etc/apt/sources.list.d/*.list

# 配置Debian 12 (bookworm)的阿里云源（与基础镜像版本匹配）
RUN echo "deb https://mirrors.aliyun.com/debian/ bookworm main contrib non-free" > /etc/apt/sources.list && \
    echo "deb-src https://mirrors.aliyun.com/debian/ bookworm main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free" >> /etc/apt/sources.list

# 安装编译mysqlclient所需的依赖（使用MariaDB兼容库）
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        gcc \
        pkg-config \
        libmariadb-dev-compat \
        libmariadb-dev \
        && rm -rf /var/lib/apt/lists/*

# 使用国内镜像源（基于实际容器路径）
# 设置pip源为清华镜像
COPY requirements.txt .
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

# 复制项目文件
COPY app.py .
COPY settings.py .
COPY db/ ./db/
COPY api/ ./api/
COPY templates/ ./templates/
COPY images/ ./images/
COPY migrations/ ./migrations/
COPY pyproject.toml .

# 设置文件权限
RUN chmod +x /app

# 暴露端口
EXPOSE 8005


# 启动命令
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8005"]

